<?php
// +----------------------------------------------------------------------
// | ZGUAN [ 致力于帮助更多的中小企业物联网转型 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.zguan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ZGUAN 并不是自由软件，未经许可不能去掉ZGUAN 相关版权
// +----------------------------------------------------------------------
// | Author: ZGUAN Team <admin@zguan.cn>  0769-82282996  15899929162
// +----------------------------------------------------------------------
namespace app\controller\api\bill;

use think\App;
use app\controller\property\Base;
use app\common\services\CacheService;
use app\common\repositories\bill\BillCateRepository;

class BillCate extends Base
{
    protected $repository;

    public function __construct(App $app, BillCateRepository $repository)
    {
        parent::__construct($app);

        $this->repository = $repository;
    }

    /**
     * 获取账单分类
     * @return mixed
     *
     * @author Amos
     * 2024-06-17 20:14
     */
    public function cateList()
    {
        $where = $this->request->param([
            'is_class' => ''
        ]);
        $where['is_show'] = 1;
        $res = CacheService::create($this->request->propertyId)
            ->remember('bill_cate_' . $this->request->propertyId . '_' . $where['is_class'], function () use ($where) {
                if ($where['is_class'] <= 0) {
                    return $this->repository->getCascaderData($this->request->propertyId, ['is_show' => 1]);
                } else {
                    return $this->repository->getCascaderData($this->request->propertyId, ['is_show' => 1, 'is_class' => $where['is_class']]);
                }
            }, 180);
        return app('api_return')->success($res);
    }

}